/*
 *  Fragmentation.h
 *  GLRender
 *
 *  Created by Patrick zulian on 5/27/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#ifndef FRAGMENTATION_H
#define FRAGMENTATION_H

#include <vector>


#include "Base.h"
#include "GLObject.h"
#include "Asteroid.h"
#include "Planet.h"

typedef struct Fragment  {
	Point3d position, velocity, rotation;
	double radius;
} Fragments;


class Fragmentation : public GLObject {
private:
	std::vector<Fragment> fragments;
	double radius, duration, theta;
	double timeElapsed;
	Point3d center, dir;
	
	bool finished;
	int numberOfFragments;
	
	WMaterial mat;
	void initFragments();
	void renderFragment(Fragment &fragment, AbstractRenderer * renderer);
	double newRandom() const;
	const Point3d newRandomPoint() const;
	const Fragment newFragment() const;
public:
	Fragmentation(WObject * asteroid);
	~Fragmentation();
	
	void step(const double tau);
	void renderOn(AbstractRenderer * renderer);
	
	inline
	bool isFinished() { return finished; }
	
	inline
	void finish() { this->finished = true; }
	
	inline
	const Point3d & getCenter() const { return center; }
};

#endif
